package com.vancouver.knows.ui.fragment.homePage;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ViewFlipper;
import com.vancouver.knows.R;
import com.vancouver.knows.business.bean.HomeLiveFeedInfo;
import com.vancouver.knows.ui.activity.homepage.livefeed.HomepageLiveFeedActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by llf on 2016/6/12.
 */
public class HomepageLiveFeedView {

    private Context mContext;
    private LayoutInflater mInflater;
    private View mView;

    @Bind(R.id.flipper_pager)
    ViewFlipper flipperPage;


    public HomepageLiveFeedView(Context context, LayoutInflater inflater) {
        mContext = context;
        mInflater = inflater;
        findViewsId();
    }

    private void findViewsId() {
        mView = mInflater.inflate(R.layout.livefeed_viewflipper, null);
        ButterKnife.bind(this, mView);
    }

    public void init(List<HomeLiveFeedInfo> listInfo){

        if (listInfo != null && listInfo.size() != 0) {
            if (listInfo.size() == 1) {
                LiveFeedViewFlipper flipperView = new LiveFeedViewFlipper(mContext);
                flipperView.initValueForOnlyOne(listInfo.get(0));
                flipperPage.addView(flipperView.getLiveFeedView());
            }else {
                for (int i = 0; i < listInfo.size(); i++) {
                    LiveFeedViewFlipper flipperView  = new LiveFeedViewFlipper(mContext);
                    flipperView.initValueForMore(listInfo.get(i));
                    flipperPage.addView(flipperView.getLiveFeedView());
                    flipperPage.startFlipping();
                }
            }
        }
    }

    @OnClick(R.id.layout_all_speek)
    public void onClickAllSpeak(){
        Intent intent = new Intent(mContext, HomepageLiveFeedActivity.class);
        intent.putExtra("ALL_SPEAKING", mContext.getString(R.string.all_speaking_title));
        mContext.startActivity(intent);

    }

    public View getLiveFeedView() {
        return mView;
    }
}
